try:
    from typing import Tuple
except ImportError:
    pass
import time

class HS3003:
    def __init__(self, i2c, address: int = 0x44) -> None:
        self._i2c = i2c
        self._address = address
        self._status_bit = None

    @property
    def measurements(self) -> Tuple[float, float]:
        """
        Return Temperature and Relative Humidity
        """
        self._i2c.writeto(self._address, bytes([0x00]))
        time.sleep(0.1)  # Time to wake up the sensor
        data = bytearray(4)
        self._i2c.readfrom_into(self._address, data)

        # The Status bit will have a value of 1 when the data is stalled
        self._status_bit = data[0] & 0x40

        msb_humidity = data[0] & 0x3F
        lsb_humidity = data[1]
        raw_humidity = msb_humidity << 8 | lsb_humidity
        humidity = (raw_humidity / (2**14.0 - 1)) * 100

        msb_temperature = data[2]
        lsb_temperature = (data[3] & 0xFC) >> 2
        raw_temperature = msb_temperature << 6 | lsb_temperature
        temperature = (raw_temperature / (2**14.0 - 1)) * 165 - 40

        return temperature, humidity

    @property
    def relative_humidity(self) -> float:
        """The current relative humidity in % rH"""
        return self.measurements[1]

    @property
    def temperature(self) -> float:
        """The current temperature in Celsius"""
        return self.measurements[0]
